package kin.converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.beanutils.Converter;

public class DateTypeConverter implements Converter{
private SimpleDateFormat sdf;
	
public DateTypeConverter(String format) {
		if(null!=format&&!"".equals(format)){
			sdf=new SimpleDateFormat("yyyy-MM-dd");
		}else{
			sdf=new SimpleDateFormat(format);
		}
	}
	public Object convert(Class cls, Object value) {
		if(cls==Date.class){
			if(value instanceof String){
			try {
				return	sdf.parse((String) value);
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			}
		}
		return null;
	}
	
	

}
